package com.itheima.edu.info.manger.controller;

import com.itheima.edu.info.manger.domain.Teacher;
import com.itheima.edu.info.manger.service.TeacherService;

import java.util.Scanner;

public class TeacherController {
    private TeacherService teacherService=new TeacherService();
    private Scanner sc=new Scanner(System.in);
    /**
     * 教师管理业务开启
     *
     */
    public void start(){
        loop:
        while(true){
            System.out.println("--------欢迎来到教师管理系统-------");
            System.out.println("1.添加教师 2.删除教师 3.修改教师 4.查看教师 5.退出");
            System.out.println("请输入你的选择");
            int choose=sc.nextInt();
            switch(choose){
                case 1:
                    addTeacher();
                    break;
                case 2:
                    System.out.println("删除教师");
                    break;
                case 3:
                    System.out.println("修改教师");
                    break;
                case 4:
                    System.out.println("查看教师");
                    break;
                case 5:
                    System.out.println("欢迎下次使用，即将返回主菜单.");
                    break loop;
                    default:
                        System.out.println("你的输入有误，请重新输入");
            }
        }
    }

    /**
     * 添加教师信息
     */
    private void addTeacher(){
        String id;
        while(true){
            System.out.println("请输入教师的工号:");
            id=sc.next();
            boolean result=teacherService.isExists(id);
            if(result){
                System.out.println("你输入的工号已经存在，请重新输入.");
            }else{
                break;
            }
        }
        System.out.println("请输入教师的姓名:");
        String name=sc.next();
        System.out.println("请输入教师的年龄:");
        String age=sc.next();
        System.out.println("请输入教师的出生日期:");
        String birthday=sc.next();
        Teacher teacher=new Teacher();
        teacher.setId(id);
        teacher.setName(name);
        teacher.setAge(age);
        teacher.setBirthday(birthday);
        boolean result=teacherService.addTeacher(teacher);
        if(result){
            System.out.println("教师的信息添加成功");
        }else{
            System.out.println("教师的信息添加失败");
        }


    }
}
